﻿Public Class Contact

    Property id As Long

    Property firstName As String
    Property lastName As String
    Property company As String
    Property title As String
    Property displayName As String
    
    Private _emailList As List(Of Email)
    Private _phoneList As List(Of PhoneNumber)
    Private _addressList As List(Of Address)

    Sub New()
        Me.New("", "", "", "", "")
    End Sub

    Sub New(fn As String, ln As String, company As String, title As String, displayName As String)
        Me.New(-1, fn, ln, company, title, displayName)
    End Sub

    Sub New(id As Long, fn As String, ln As String, company As String, title As String, displayName As String)

        Me._id = id
        Me._firstName = fn
        Me._lastName = ln
        Me._company = company
        Me._title = title
        Me._displayName = displayName

    End Sub

    Public ReadOnly Property emailList As List(Of Email)
        Get
            If IsNothing(Me._emailList) Then
                Me._emailList = New List(Of Email)
            End If
            Return Me._emailList
        End Get
    End Property

    Public ReadOnly Property phoneList As List(Of PhoneNumber)
        Get
            If IsNothing(Me._phoneList) Then
                Me._phoneList = New List(Of PhoneNumber)
            End If
            Return Me._phoneList
        End Get
    End Property

    Public ReadOnly Property addressList As List(Of Address)
        Get
            If IsNothing(Me._addressList) Then
                Me._addressList = New List(Of Address)
            End If
            Return Me._addressList
        End Get
    End Property

    Function isNew() As Boolean
        Return (Me._id = -1)
    End Function

    Function phoneIds() As String

        If (phoneList.Count = 0) Then
            Return ""
        End If

        Dim phoneIdCsv As String = ""
        For Each phone In phoneList
            phoneIdCsv += phone.id & ","
        Next
        Return phoneIdCsv.Substring(0, phoneIdCsv.Length - 1)

    End Function

    Function emailIds() As String

        If (emailList.Count = 0) Then
            Return ""
        End If

        Dim emailIdCsv As String = ""
        For Each email In emailList
            emailIdCsv += email.id & ","
        Next
        Return emailIdCsv.Substring(0, emailIdCsv.Length - 1)

    End Function

    Function addressIds() As String

        If (addressList.Count = 0) Then
            Return ""
        End If

        Dim addressIdCsv As String = ""
        For Each address In addressList
            addressIdCsv += address.id & ","
        Next
        Return addressIdCsv.Substring(0, addressIdCsv.Length - 1)

    End Function

    

End Class
